package com.iaz.tech.tools.ai.neuron.exec;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iaz.tech.tools.ai.neuron.runtime.INeuronRuntimeAbility; 
import com.iaz.tech.tools.common.utils.UtilTools;
import com.iaz.tech.tools.property.project.Project;
import com.iaz.tech.tools.uml.IUMLNeuronAble;
import com.iaz.tech.tools.uml.relationship.Relationship;
import com.iaz.tech.tools.uml.structural.pack.impl.NeuronPackage;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Package 生成工具
 */
@EqualsAndHashCode(callSuper=false)
@Data
public class NeuronPackageCodeGenerator extends NeuronCodeGenerator {
    /**
     * 日志
     */
	private final static Logger logger = (Logger) LoggerFactory.getLogger(NeuronPackageCodeGenerator.class);
    
    public NeuronPackageCodeGenerator() {
        super();
    }

    public NeuronPackageCodeGenerator(INeuronRuntimeAbility runtime) {
        super();
        this.setRuntime(runtime);
    }

    @Override
    public Relationship toRelationship(IUMLNeuronAble uml) throws Exception {
        throw new IllegalArgumentException("uml必须为Class");
    }

    @Override
    public String generateSourceCode(Project project,IUMLNeuronAble uml) {
        String result = "";
        try {
            if (uml == null) {
                throw new IllegalArgumentException("uml不能为null");
            }
            if (!(uml instanceof NeuronPackage)){
                throw new IllegalArgumentException("uml必须为Package");
            }
            if (this.getRuntime() == null){
                throw new IllegalArgumentException("runtime不能为null");
            }
            NeuronPackage pack = (NeuronPackage) uml;
            if (UtilTools.IsNull(pack.getPath())) {
                throw new IllegalArgumentException("Package路径不能为null");
            }
            result = pack.getPath();
            /* 创建目录 */
            UtilTools.createNewPaths(result);
        }catch(Exception e) {
            logger.error("生成Package代码失败", e);
            result = "";
        }
        return result;
    }

}
